package org.example.theory.controller;

import org.example.theory.model.Dog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope;

@RestController
@RequestMapping("/dog")
public class DogController {
    @Autowired
    public ApplicationContext context;

    @RequestMapping("singleton")
    public String singleton() {
        Dog dog1 = context.getBean("singletonDog", Dog.class);
        Dog dog2 = context.getBean("singletonDog", Dog.class);
        return "dog1: " + dog1.toString() + "<br/>" + "dog2: " + dog2.toString();
    }


    @RequestMapping("/property")
    public String property() {
        Dog dog1 = context.getBean("propertyDog", Dog.class);
        Dog dog2 = context.getBean("propertyDog", Dog.class);
        return "dog1: " + dog1.toString() + "<br/>" + "dog2: " + dog2.toString();
    }

    @RequestMapping("/request")
    public String request() {
        Dog dog1 = context.getBean("requestDog", Dog.class);
        Dog dog2 = context.getBean("requestDog", Dog.class);
        return "dog1: " + dog1.toString() + "<br/>" + "dog2: " + dog2.toString();
    }

    @RequestMapping("/session")
    public String session() {
        Dog dog1 = context.getBean("sessionDog", Dog.class);
        Dog dog2 = context.getBean("sessionDog", Dog.class);
        return "dog1: " + dog1.toString() + "<br/>" + "dog2: " + dog2.toString();
    }

    @RequestMapping("/application")
    public String application() {
        Dog dog1 = context.getBean("applicationDog", Dog.class);
        Dog dog2 = context.getBean("applicationDog", Dog.class);
        return "dog1: " + dog1.toString() + "<br/>" + "dog2: " + dog2.toString();
    }
}
